//-----------------------------------------------------------------------
// <copyright file="ApplicationMessageFactory.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace Microsoft.Live.Messenger.Messaging
{
    using System;
    using Microsoft.Live.Messenger;

    /// <summary>
    ///     A factory class that must be derived from in order to implement custom messages. The factory
    ///     takes care of deserializing incoming messages and allows for registering and promoting messages
    ///     to other applications.
    /// </summary>
    public abstract class ApplicationMessageFactory
    {
        /// <summary>
        ///     Initializes a new <see cref="ApplicationMessageFactory"/> instance.
        /// </summary>
        /// <param name="User">The User this factory is for</param>
        protected ApplicationMessageFactory(
            User user)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        ///     Registers the ID for a custom message. Once an ID has been registered, it will be promoted to 
        ///     other applications to make them aware your application supports the given custom message.
        /// </summary>
        /// <param name="id">The ID to register</param>
        /// <remarks>
        ///     The maximum length of an ID is 64 characters.
        /// </remarks>
        public void Register(string id)
        {
        }

        /// <summary>
        ///     Unregisters an ID, might your application no longer support it.
        /// </summary>
        /// <param name="id">The ID to register</param>
        public void Unregister(string id)
        {
        }

        /// <summary>
        ///     Checks if a given ID has already been registered.
        /// </summary>
        /// <param name="id">The ID to check for</param>
        /// <returns><c>true</c> if registered; <c>false</c> otherwise.</returns>
        public bool IsRegistered(string id)
        {
            return false;
        }

        /// <summary>
        ///     Deserializes an incoming custom message.
        /// </summary>
        /// <param name="sender">The sender of the message.</param>
        /// <param name="id">The ID of the incoming message (The ID will be lower cased).</param>
        /// <param name="content">The serialized content of the message.</param>
        /// <returns>A new <see cref="ApplicationMessage"/>, or <c>null</c> if the message is unrecognized or invalid.</returns>
        protected internal abstract ApplicationMessage Deserialize(
            IMAddress sender,
            string id,
            string content);

        /// <summary>
        ///     Serializes an outgoing custom message.
        /// </summary>
        /// <param name="message">The message to serialize</param>
        /// <remarks>
        ///     The string that this method returns is what ultimately gets sent to another buddy. Keep in 
        ///     mind that the data <see cref="Serialize"/> returns must be deserialized on the other end to 
        ///     create the message object.
        /// </remarks>
        protected internal abstract string Serialize(
            ApplicationMessage message);
    }
}